package com.lk.recvice.handler.impl;

import com.alibaba.fastjson.JSONObject;
import com.lk.base.utils.SpringBeanFactoryUtils;
import com.lk.base.utils.StringUtil;
import com.lk.recvice.handler.OtaManager;
import com.lk.recvice.mq.sender.ReportDataSender;
import com.lk.recvice.server.MyServerSocket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

public class DatasManager implements OtaManager{

	Logger logger = LoggerFactory.getLogger(this.getClass());

	@Override
	public Object doWork(JSONObject jsonObject) {
		if(!MyServerSocket.deviceMaps.containsKey(jsonObject.getString("snId"))) {
			logger.debug("SNID：:" + jsonObject.getString("snId") + "不存在，无法连接发送数据");
			return null;
		}
		//第一步：获取数据后进行首次处理
		logger.debug("数据:" + jsonObject.toJSONString());
		jsonObject.put("reivceTime", new Date());
		jsonObject.put("type", "datas");
		//发送的MQ消息不能为空
		if(!StringUtil.isEmpty(jsonObject.toJSONString())) {

			ReportDataSender sender = SpringBeanFactoryUtils.getBean(ReportDataSender.class);
			sender.doSend(jsonObject.toJSONString());

		}
		return null;
	}

	@Override
	public OtaManager init() {
		return this;
	}



}
